<?php
namespace app\wechat\controller;
use app\wechat\controller\BaseController;
use app\wechat\model\WechatModel as Wechat;

/**
 * 
 */
class IndexController extends BaseController
{
	
	function __construct()
	{
		parent::__construct();
		$this->request=request();
		$this->param=request()->param();
		$this->options=[
				'token'=>'weixin',	//填写应用接口的Token
		        'encodingaeskey'=>'encodingaeskey',//填写加密用的EncodingAESKey
		        'appid'=>'wx2cbbdb21369b1a10',	//填写高级调用功能的appid
		        'appsecret'=>'ff0f4e544a632685b1e5223000443db1', //填写高级调用功能的密钥
		        'agentid'=>'1', //应用的id
				'debug'=>true, //调试开关
				'_logcallback'=>'logg', //调试输出方法，需要有一个string类型的参数
		    ];
		// $this->model=new Wechat($this->options);
	}
	
	public function indexAction(){ 
		$wechat=new Wechat($this->options);
		// $wechat->valid();
	$type = $wechat->getRev();
	$wechat->music('不仅仅是喜欢','不仅仅是喜欢-虎二','http://fs.w.kugou.com/201806220459/4d92a7d107c5473486143655f26a7094/G123/M0A/1A/08/G4cBAFsp97WAMWxiAEURHVT3DRg816.mp3','','')->reply();die;
	switch($type) {
		case Wechat::MSGTYPE_TEXT:
				$wechat->text("hello, I'm wechat")->reply();
				exit;
				break;
		case Wechat::MSGTYPE_EVENT:
				break;
		case Wechat::MSGTYPE_IMAGE:
				break;
		default:
				$wechat->text("help info")->reply();
			}

				die;
		$wechat->getRev();
		$wechat->text('nnn')->reply();
		var_dump($wechat);die;
		$wechat->getRev()->news([
			'Title'=>'msg title',
			'Description'=>'summary text',
			'PicUrl'=>'http://www.domain.com/1.jpg',
			'Url'=>'http://www.domain.com/1.html'
		])->reply();
		die;
		
		$method=request()->param('method');
		$res=$wechat->$method();
		var_dump($res);
	}

	public function createMenuAction(){
		if ($this->request->isPost()) {
			$wechat=new Wechat($this->options);
			$menu=[
				'button'=>[
					['name'=>'开始游戏','sub_button'=>[
						['name'=>'一个人？加入玩家群','type'=>'click','key'=>'001'],
						['name'=>'随机分配','type'=>'click','key'=>'001'],
						['name'=>'好友组队','type'=>'click','key'=>'001'],
					]],
					['name'=>'投票','type'=>'click','key'=>'001'],
					['name'=>'帮助','type'=>'click','key'=>'001'], 
				],
			]; 
			$wechat->createMenu($menu);
			var_dump($wechat);
		}
		return $this->fetch();
	}


	public function uploadMediaAction(){
		if ($this->request->isPost()) {
			$wechat=new Wechat($this->options);
			$wechat->uploadMedia($data,'image');
		}
		return $this->fetch();
	}

}